package com.speech.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.ListView;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.speech.R;
import com.speech.adapter.PropertyRankingAdapter;
import com.speech.item.PropertyRankingItem;
import com.speech.net.BasicCallBack;
//import com.speech.net.HttpCommunicationManager;
import com.speech.net.constant.EnumReqestActionCode;
import com.speech.net.entity.MessageC2S;
import com.speech.net.entity.MessageC2SBuilder;
import com.speech.net.entity.MessageS2C;
import com.speech.utils.JsonProcessor;
import com.speech.utils.TitleBuilder;
import com.speech.net.result.UserPropertyRankData;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class PropertyRankingActivity extends BaseActivity {

    private ListView lv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ranking);

        _initView();

        //申报排行榜
        Double d = 100.10;


        //TODO: 接口请求
//        MessageC2S msg_c2s = MessageC2SBuilder.buildGeneral_MessageC2S(this, EnumReqestActionCode.申报排行榜,"{\"todays_property\":"+d+"}");
//        String json = JsonProcessor.StcGetJson(msg_c2s);
//        HttpCommunicationManager.getInstance().doPost(json,new BasicCallBack(PropertyRankingActivity.this, json, new BasicCallBack.BasicCallBackListener() {
//            @Override
//            public void success(MessageS2C msg_s2c) {
//
//                //获取排行榜
//                MessageC2S msg_c2s = MessageC2SBuilder.buildGeneral_MessageC2S(PropertyRankingActivity.this,EnumReqestActionCode.获取排行榜,null);
//                String json = JsonProcessor.StcGetJson(msg_c2s);
//                HttpCommunicationManager.getInstance().doPost(json,new BasicCallBack(PropertyRankingActivity.this, json, new BasicCallBack.BasicCallBackListener() {
//                    @Override
//                    public void success(MessageS2C msg_s2c) {
//
//                        ObjectMapper mapper = new ObjectMapper();
//                        List<UserPropertyRankData> lst_rst = null;
//                        try {
//                            lst_rst = mapper.readValue(msg_s2c.strData, new TypeReference<List<UserPropertyRankData>>() {});
//                        } catch (IOException e) {
//                            e.printStackTrace();
//                        }
//
//                        UserPropertyRankData data = lst_rst.get(0);
//                        System.out.println(data.dProperty+"");
//
//                        //TODO:临时的数据
//                        List<PropertyRankingItem> lst_data = new ArrayList<>();
//                        for (int i = 1; i <= 10; i++) {
//                            PropertyRankingItem item = new PropertyRankingItem();
//                            item.iResIconID = _get_res_icon_id(i);
//                            item.strHeadUrl = "http://www.runoob.com/wp-content/uploads/2015/09/19131609.jpg";
//                            item.strNickName = "abc123";
//                            item.strInviteNum = "99";
//                            item.strProperty = "1000";
//                            lst_data.add(item);
//                        }
//
//                        PropertyRankingAdapter adapter = new PropertyRankingAdapter(lst_data, PropertyRankingActivity.this);
//                        lv.setAdapter(adapter);
////                        lv.notifyAll();
//
//                    }
//
//                    @Override
//                    public void fail(MessageS2C msg_s2c) {
//
//                    }
//                }));
//
//            }
//
//            @Override
//            public void fail(MessageS2C msg_s2c) {
//
//            }
//        }));


    }

    private void _initView() {
        new TitleBuilder(this).setTitleText("昨日排行榜前十");

        lv = findViewById(R.id.lv_ranking);

    }

    private int _get_res_icon_id(int i) {
        switch (i) {
            case 1:
                return R.drawable.ranking_icon_1;
            case 2:
                return R.drawable.ranking_icon_2;
            case 3:
                return R.drawable.ranking_icon_3;
            case 4:
                return R.drawable.ranking_icon_4;
            case 5:
                return R.drawable.ranking_icon_5;
            case 6:
                return R.drawable.ranking_icon_6;
            case 7:
                return R.drawable.ranking_icon_7;
            case 8:
                return R.drawable.ranking_icon_8;
            case 9:
                return R.drawable.ranking_icon_9;
            case 10:
                return R.drawable.ranking_icon_10;
        }
        return R.drawable.ranking_icon_10;
    }
}
